package com.info.zhiduoduo.repository.mapper.company;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Condition;
import com.info.zhiduoduo.repository.dto.company.CompanyZhaoShangSubLedgerDto;
import com.info.zhiduoduo.repository.entity.company.CompanyZhaoshangSubLedger;

import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface CompanyZhaoshangSubLedgerMapper extends BaseMapper<CompanyZhaoshangSubLedger> {

	default CompanyZhaoshangSubLedger findByCompidAndMerchantId(int compid, int merchantId) {
		return new CompanyZhaoshangSubLedger().selectOne(Condition.create().eq("compid", compid).eq("merchant_id", merchantId));
	}

	@Select(" SELECT * from zdd_company_zhaoshang_sub_ledger where state = 1 ")
	List<CompanyZhaoshangSubLedger> listAllCreating();

	@Select(" SELECT * from zdd_company_zhaoshang_sub_ledger where state = 2 ")
	List<CompanyZhaoshangSubLedger> listAllCreated();

	@Select(" select czsl.*,pm.name as merchantName " +
			" from zdd_company_zhaoshang_sub_ledger czsl " +
			" join zdd_payment_merchant pm on pm.id = czsl.merchant_id " +
			" where if(#{compid} = 0, 1=1, czsl.compid = #{compid}) " +
			" and czsl.ledger_name like '%${compname}%' " +
			" and if(#{merchantId} = 0, 1=1, czsl.merchant_id = #{merchantId}) " +
			" and czsl.createtime between #{from} and #{to}")
	List<CompanyZhaoShangSubLedgerDto> listByMerchantIdAndCompname(int compid, String compname, int merchantId, Date from, Date to);

	@Select(" select * from zdd_company_zhaoshang_sub_ledger where ledger_no = #{ledgerNo}")
	CompanyZhaoshangSubLedger findByLedgerNo(String ledgerNo);
}
